import {toast} from "~/uilti/tool"
import store from "~/store"
import Cookies from 'js-cookie'
import {router} from "~/router/index"

router.beforeEach((to, from, next) => {
    const token = Cookies.get('token')
    const manner = sessionStorage.getItem('manner')
    if (!(token || manner) && to.meta.requireAuth) {
        toast('请先登录', "error")
        return next({path: '/login'})
    }
    if ((token || manner) && to.path == '/login') {
        toast('请勿重复登录', "error")
        return next({path: from.path ? from.path : '/home'})
    }
    //如果用户登录，存储信息vuex中
    if (token || manner) {
        store.dispatch('getinfo')
    }
//
// //网页页签
//     let title = to.meta.title ? to.meta.title : '暂无'
//     document.title = title
    next()
})
